<template>
	<view>
		<page-head :title="'我的收藏'" :headtype="2"></page-head>
		<view class="goodslist">
			<view class="goodseach marginAuto blockbg" v-for="(item,index) in goodsdata" :key="index">
				<view class="goodslmsg">
					<view class="closecollect" @click="closecollfun(item,index)">
						取消收藏
					</view>
					<view class="goodslmsg-photo" @click="apifun.navigate('/pages/homeList/detailedness/detailedness','type=1&id='+item.id)">
						<image :src="URLimg + item.image" mode="aspectFill"></image>
					</view>
					<view class="goodslmsg-msg" @click="apifun.navigate('/pages/homeList/detailedness/detailedness','type=1&id='+item.id)">
						<view class="goodslmsg-name ellipsis01" style="width:60%;">{{ item.name }}</view>
						<view class="goodslmsg-money">￥{{ item.sell_price }}</view>
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				URLimg:this.URLimg,
				apifun:this.apifun,
				page:1,
				goodsdata:[]
			};
		},
		onLoad() {
			this.initData()
		},
		methods: {
			closecollfun(item,index){  // 取消收藏
				let sendData = {
					goods_id:item.id
				};
				this.apifun.unirequest('/api/goods/collect','post',sendData,(res)=>{
					// console.log(res)
					if(res.code === 200){
						let datas = res.data;
						this.apifun.toast('取消成功');
						this.goodsdata.splice(index,1);
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			initData(){ 
				let sendData = {
					page:this.page
				};
				this.apifun.unirequest('/api/goods/getGoodsCollectList','post',sendData,(res)=>{
					// console.log(res)
					if(res.code === 200){
						let datas = res.data;
						if(datas.data.lenth <= 0){
							this.page--;
							return false
						};
						this.goodsdata.push(...datas.data);
					}else{
						this.apifun.toast(res.msg)
					}
				})
			}
		},
		onReachBottom() {
			this.page++;
			this.initData();
		},
		onPullDownRefresh() {
			this.page = 1;
			this.goodsdata = [];
			this.initData();
			uni.stopPullDownRefresh();
		},
	};
</script>

<style scoped lang="scss">
	page{
		padding-bottom: 100rpx;
	}
	.blockbg {
		width: 640rpx;
		border-radius: 18rpx;
		background-color: #fff;
		padding: 24rpx;
	}
	.goodseach {
		margin-top: 20rpx;
		.goodslmsg {
			position: relative;
			display: flex;
			padding: 10rpx 0;
			.goodslmsg-photo,
			.goodslmsg-photo image {
				position: relative;
				width: 216rpx;
				height:216rpx;
				margin-right: 10rpx;
				border-radius: 20rpx;
			}
			.goodslmsg-msg {
				position: relative;
				width:70%;
				margin-left: 10rpx;
				.goodslmsg-name {
					color: #333333;
					font-size: 30rpx;
					font-weight: 400;
					line-height: 40rpx;
					margin-top: 5rpx;
				}
				.goodslmsg-money{
					position: absolute;
					bottom:5rpx;
					font-size:36rpx;
					color: #D31E11;
				}
			}
			.closecollect{
				position:absolute;
				bottom: 0;
				right: 0;
				z-index: 1;
				width:172rpx;
				height: 66rpx;
				line-height: 66rpx;
				border-radius: 100rpx;
				background-color:#E2E2E2;
				color:#979797;
				text-align: center;
			}
		}
	}
</style>